package com.kemai.designmode.ui
import android.os.Bundle
import com.alibaba.fastjson.JSON
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.common.utils.AppUtils
import com.kemai.designmode.R
import com.kemai.designmode.composite.AdministrativeArea
import com.kemai.designmode.composite.Area
import org.json.JSONObject

//组合模式调用(把一组相似的对象当作一个单一的对象)
class CompositeActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("生成行政区域数据")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("组合模式")
        setAdapterContent(studyContent,CompositeActivity@this,CompositeActivity@this)
    }

    override fun itemClick(position: Int) {
        when(position){
            0->{
                val root = AdministrativeArea("area")
                root.addChildren(AdministrativeArea("北京"))
                root.addChildren(AdministrativeArea("上海"))
                val wuHanRoot = AdministrativeArea("武汉")
                root.addChildren(wuHanRoot)

                wuHanRoot.addChildren(AdministrativeArea("红山区"))
                wuHanRoot.addChildren(AdministrativeArea("青山区"))
                val wuHanStreetRoot = AdministrativeArea("东西湖区")
                wuHanRoot.addChildren(wuHanStreetRoot)

                wuHanStreetRoot.addChildren(AdministrativeArea("螃蟹岬"))
                wuHanStreetRoot.addChildren(AdministrativeArea("昙华林"))
                wuHanStreetRoot.addChildren(AdministrativeArea("九峰"))
                AppUtils.getInstance()?.showToast(JSON.toJSONString(root))
                println(JSON.toJSONString(root))



            }
        }
    }

}